//
//  OrderDetailViewController.m
//  PaiLeXiongProject
//
//  Created by 小獾科技 on 2017/9/14.
//  Copyright © 2017年 小獾科技. All rights reserved.
//

#import "OrderDetailViewController.h"

@interface OrderDetailViewController ()
@property (nonatomic, strong) UILabel *moneyLabel;
@property (nonatomic, strong) UILabel *goodsName;
@property (nonatomic, strong) UILabel *orderNumber;
@property (nonatomic, strong) UIImageView *codeImg;//二维码
@end

@implementation OrderDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"订单详情";
    [self addBackItem];
    [self initView];
    
    [self startNetwork];
}

- (void)startNetwork
{
    [NetWork sendGetRequestURL:[NSString stringWithFormat:@"%@/order/getOrderDet?orderSn=%@", GW_Domain, self.ordersn] parameters:@{@"orderSn":self.ordersn} completionBlockWithSuccess:^(NSDictionary *resultDict) {
        NSDictionary *dic = resultDict[@"data"];
        _goodsName.text = [NSString stringWithFormat:@"商品名称 %@", dic[@"goods_name"]];
        _orderNumber.text = [NSString stringWithFormat:@"订单号 %@", dic[@"orderSn"]];
       
        NSLog(@"支付成功 %@", dic);
        
        NSString *str = [NSString stringWithFormat:@"%@", STRING(dic[@"qccode"])];
        str = [NetWork handleUrlStr:str withDict:nil];
        NSLog(@"拼接链接 %@", str);
        
        [_codeImg sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:nil];
        
        
    } andFailure:^(NSError *error, NSString *errorMsg) {
        NSLog(@"%@", errorMsg);
    }];
}

- (void)initView
{
    _moneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, GWIDTH, 78)];
    _moneyLabel.text = @"订单金额:￥478";
    _moneyLabel.textColor = ColorFrom16(0x323232);
    _moneyLabel.font = PFRFONT(18);
    _moneyLabel.textAlignment = 1;
    [self.view addSubview:_moneyLabel];
    
    UIView *line = [UIView new];
    line.backgroundColor = COLOR_BACKGROUND;
    [self.view addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_moneyLabel.mas_bottom);
        make.left.and.right.equalTo(self.view);
        make.height.equalTo(@1);
    }];
    
    _goodsName = [UILabel new];
    _goodsName.text = @"商品名称  爱儿美儿童舞蹈秋季梦想儿童舞蹈";
    _goodsName.textColor = ColorFrom16(0x757982);
    _goodsName.font = PFRFONT(14);
    [self.view addSubview:_goodsName];
    [_goodsName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(line.mas_bottom);
        make.left.equalTo(self.view).offset(10);
        make.right.equalTo(self.view).offset(-10);
        make.height.equalTo(@44);
    }];
    
    UIView *line1 = [UIView new];
    line1.backgroundColor = COLOR_BACKGROUND;
    [self.view addSubview:line1];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_goodsName.mas_bottom);
        make.left.and.right.equalTo(self.view);
        make.height.equalTo(@1);
    }];
    
    _orderNumber = [UILabel new];
    _orderNumber.text = @"订单号 493499429912345865436789";
    _orderNumber.textColor = ColorFrom16(0x757982);
    _orderNumber.font = PFRFONT(14);
    _orderNumber.attributedText = [GW_Tool setTextSpace:_orderNumber.text textSpaceSize:3.79];
    [self.view addSubview:_orderNumber];
    [_orderNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(line1.mas_bottom);
        make.left.equalTo(self.view).offset(10);
        make.right.equalTo(self.view).offset(-10);
        make.height.equalTo(@44);
    }];
    
    UIView *line2 = [UIView new];
    line2.backgroundColor = COLOR_BACKGROUND;
    [self.view addSubview:line2];
    [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_orderNumber.mas_bottom);
        make.left.and.right.equalTo(self.view);
        make.height.equalTo(@1);
    }];
    
    _codeImg = [UIImageView new];
    _codeImg.image = IMAGE(@"");
    [self.view addSubview:_codeImg];
    [_codeImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(line2.mas_bottom).offset(55);
        make.centerX.equalTo(self.view.mas_centerX);
        make.width.equalTo(@150);
        make.height.equalTo(@140);
    }];
    
    UILabel *label = [UILabel new];
    label.text = @"向商家出示以上消费券即可消费";
    label.textColor = ColorFrom16(0x757982);
    label.font = PFRFONT(10);
    [self.view addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_codeImg.mas_bottom).offset(14);
        make.centerX.equalTo(_codeImg.mas_centerX);
        make.width.equalTo(@145);
        make.height.equalTo(@14);
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
